package com.FrameWork.Common;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

import com.SFA.R;
import com.umeng.analytics.MobclickAgent;

public class AbstractBaseActivity extends Activity
{
	public Dialog dialog = null;
	//当前页面上下文
	public Context context= null;

	public MyApplication app = null;
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Intent intent = getIntent();
		if(intent!= null)
		{
			String title = intent.getStringExtra("title");
			if(title != null)
				this.setTitle(title);
			TextView tvTitle = (TextView) this.findViewById(R.id.txv_title);
			if(tvTitle!= null)
				tvTitle.setText(title);
		}
	}
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		context = this;
		app = (MyApplication) getApplication(); 
		MyApplication.setInstance(app);
		app.addActivity(this);
		//requestWindowFeature(Window.FEATURE_NO_TITLE);  

		ActionBar bar = getActionBar();
		bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO| ActionBar.DISPLAY_HOME_AS_UP| ActionBar.DISPLAY_SHOW_TITLE);
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		bar.setDisplayShowHomeEnabled(true);
		bar.setDisplayUseLogoEnabled(true);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {

		case android.R.id.home:
			if(this instanceof MainActivity)
			{
				return true;
			}
			if(MyApplication.getInstance().activityList.size()>1)
			{
				Activity activity = MyApplication.getInstance().activityList.get(MyApplication.getInstance().activityList.size()-2);
				if(activity != null && activity instanceof MainActivity)
				{
					finish();
					return true;
				}
			}
			Intent intent = new Intent(this,MainActivity.class);
			finish();
			this.startActivity(intent);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}

	}
	@Override
	protected void onPause()
	{
		super.onPause();
		//使用友盟统计功能
		MobclickAgent.onPause(this);
	}

	@Override
	protected void onResume()
	{
		super.onResume();
		//使用友盟统计功能
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		app.activityList.remove(this);
	}


}
